<%--
  Created by IntelliJ IDEA.
  User: cz
  Date: 2021/8/12
  Time: 10:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>图书系统首页</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <script src="js/jquery-3.6.0.js"></script>
</head>
<body style="background-color: rgba(174,174,174,0.55)">
<div class="page-header">
    <h1>图书管理界面</h1>
</div>

<table class="table table-striped">
    <thead>
    <tr>
        <th>id</th>
        <th>图书名称</th>
        <th>作者</th>
        <th>出版社</th>
        <th>出版时间</th>
        <th>是否被借阅</th>
        <th>当前借阅人id</th>
        <th>操作</th>
    </tr>
    </thead>

    <tbody id="tbody">
    </tbody>
</table>
<a href="/addBook.jsp" class="btn btn-primary btn-lg active" role="button">添加新图书</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="/managerSystem.do?flag=preDeleteBook" class="btn btn-primary btn-lg active" role="button">删除图书</a>

<br>
<br>
<br>
<a href="/logout.do" class="btn btn-default btn-lg active" role="button">退出登录</a>

</body>
</html>
<script>
    $(function () {
        //获取页面初始化值
        getData();
    });

    function getData() {
        //获取页面初始化值
        $.getJSON("managerSystem.do",{flag:"init"},function (result) {
            init(result);
        })
    }

    function init(data) {
        console.log(data);
        var data_length = data.length;
        for (var i = 0;i<data_length;i++){
            if (data[i].readId!=0){
                $("#tbody").append("<tr>" +
                    "<td>" +data[i].bookId+"</td>"+
                    "<td>" +data[i].bookName+"</td>"+
                    "<td>" +data[i].author+"</td>"+
                    "<td>" +data[i].publisher+"</td>"+
                    "<td>" +data[i].pubDate+"</td>"+
                    "<td>是</td>"+
                    "<td>" +data[i].readId+"</td>"+
                    "<td><a href='/bookSystem.do?flag=borrow&bookId="+data[i].bookId+"' class='btn btn-default btn-lg active' role='button'>修改图书</a></td>" +
                    "</tr>"
                )
            }else {
                $("#tbody").append("<tr>" +
                    "<td>" + data[i].bookId + "</td>" +
                    "<td>" + data[i].bookName + "</td>" +
                    "<td>" + data[i].author + "</td>" +
                    "<td>" + data[i].publisher + "</td>" +
                    "<td>" + data[i].pubDate + "</td>" +
                    "<td>否</td>" +
                    "<td>" + data[i].readId + "</td>" +
                    "<td><a href='/bookSystem.do?flag=borrow&bookId=" + data[i].bookId + "' class='btn btn-default btn-lg active' role='button'>修改图书</a></td>" +
                    "</tr>"
                )
            }
        }
    }
</script>

